package aloyii.demo2.before;

/**
 * @Author yajing zhu
 * @Date 2024/10/21 14:14
 * @Version 1.0
 * @注释：
 */
public class RectangleDemo {
    public static void main(String[] args) {
        // 创建矩形对象
        Rectangle rectangle = new Rectangle();
        rectangle.setWidth(10);
        rectangle.setLength(20);
        resize(rectangle);
        printLengthAndWidth(rectangle);
        
        // 创建正方形对象
        Square square = new Square();
        square.setLength(10);
        square.setWidth(10);
        resize(square);
        printLengthAndWidth(square);
    }
    
    // 扩宽方法
    public static void resize(Rectangle rectangle) {
        //判断宽如果比长小，进行扩宽的操作
        while (rectangle.getWidth() <= rectangle.getLength()) {
            rectangle.setWidth(rectangle.getWidth() + 1);
        }
    }
    
    // 打印长和宽
    public static void printLengthAndWidth(Rectangle rectangle) {
        System.out.println(rectangle.getLength());
        System.out.println(rectangle.getWidth());
    }
}
